package com.cdut.logistics.action.businesses;

import java.util.List;

import com.cdut.logistics.intercepter.system.AuthorityIntercepter;
import com.cdut.logistics.model.entity.Model.News;
import com.cdut.logistics.service.interf.businesses.NewsService;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
@Before(AuthorityIntercepter.class)
public class NewsController extends Controller {
	NewsService newsService;
	/**
	 * 
	 */
    public void index()
    {
    	render("");
    }
    
    /**
     * String title,String url,String content,String img_id,String video_url,int sort
     */
    public void news_create()
    {
    	String title= getPara("title");
    	String url= getPara("url");
    	String content= getPara("content");
    	String img_id= getPara("img_id");
    	String video_url= getPara("video_url");
    	int sort= getParaToInt("sort");
    	
    	boolean is_success = newsService.news_create(title, url, content, img_id, video_url, sort);
    	
    	setAttr("is_success",is_success);
    	renderJson();
    	
    }
    
    /**
     * 
     */  
    public void news_update()
    {
    	String title= getPara("title");
    	String url= getPara("url");
    	String content= getPara("content");
    	String img_id= getPara("img_id");
    	String video_url= getPara("video_url");
    	int sort= getParaToInt("sort");
    	int news_id = getParaToInt("news_id");
    	
    	boolean is_success = newsService.news_update(news_id,title, url, content, img_id, video_url, sort);
    	
    	setAttr("is_success",is_success);
    	renderJson();
    }
    
    /**
     * 
     */
    public void news_delete()
    {
    	int news_id = getParaToInt("news_id");
        
    	boolean is_success = newsService.news_delete(news_id);
    	
    	setAttr("is_success",is_success);
    	renderJson();
    }
    /**
     * 
     */
    public void news_search()
    {
        List<News> list = newsService.news_search();
    	
    	setAttr("list",list);
    	renderJson();
    }
    
    public void news_detail()
    {
    	int news_id = getParaToInt("news_id");
    	
        News news = newsService.news_search(news_id);
    	
    	setAttr("news",news);
    	renderJson();
    }
}
